<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.11.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>cppMISC: include/threadPool.hpp 源文件</title>
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../cookie.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript" src="../../darkmode_toggle.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectalign">
   <div id="projectname">cppMISC<span id="projectnumber">&#160;v1.1</span>
   </div>
   <div id="projectbrief">cppMisc 文档系统</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.11.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(1); });
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
  initMenu('../../',true,false,'search.php','搜索',false);
  $(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">载入中...</div>
<div class="SRStatus" id="Searching">搜索中...</div>
<div class="SRStatus" id="NoMatches">未找到</div>
</div>
</div>
</div>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="headertitle"><div class="title">threadPool.hpp</div></div>
</div><!--header-->
<div class="contents">
<a href="../../dd/dce/thread_pool_8hpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno">    1</span> </div>
<div class="line"><a id="l00007" name="l00007"></a><span class="lineno">    7</span><span class="preprocessor"> #pragma once</span></div>
<div class="line"><a id="l00008" name="l00008"></a><span class="lineno">    8</span><span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><a id="l00009" name="l00009"></a><span class="lineno">    9</span><span class="preprocessor">#include &lt;queue&gt;</span></div>
<div class="line"><a id="l00010" name="l00010"></a><span class="lineno">   10</span><span class="preprocessor">#include &lt;thread&gt;</span></div>
<div class="line"><a id="l00011" name="l00011"></a><span class="lineno">   11</span><span class="preprocessor">#include &lt;mutex&gt;</span></div>
<div class="line"><a id="l00012" name="l00012"></a><span class="lineno">   12</span><span class="preprocessor">#include &lt;condition_variable&gt;</span></div>
<div class="line"><a id="l00013" name="l00013"></a><span class="lineno">   13</span><span class="preprocessor">#include &lt;atomic&gt;</span></div>
<div class="line"><a id="l00014" name="l00014"></a><span class="lineno">   14</span><span class="preprocessor">#include &lt;functional&gt;</span></div>
<div class="line"><a id="l00015" name="l00015"></a><span class="lineno">   15</span><span class="preprocessor">#include &lt;future&gt;</span></div>
<div class="line"><a id="l00016" name="l00016"></a><span class="lineno">   16</span><span class="preprocessor">#if defined( __WIN32 ) || defined( __WIN64 )</span></div>
<div class="line"><a id="l00017" name="l00017"></a><span class="lineno">   17</span><span class="preprocessor">#   include &lt;windows.h&gt;</span></div>
<div class="line"><a id="l00018" name="l00018"></a><span class="lineno">   18</span><span class="preprocessor">#endif</span></div>
<div class="line"><a id="l00019" name="l00019"></a><span class="lineno">   19</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../df/d8d/namespacewheels.html">wheels</a></div>
<div class="line"><a id="l00020" name="l00020"></a><span class="lineno">   20</span>{</div>
<div class="foldopen" id="foldopen00021" data-start="{" data-end="};">
<div class="line"><a id="l00021" name="l00021"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html">   21</a></span>    <span class="keyword">class </span><a class="code hl_class" href="../../dd/d3f/classwheels_1_1thread_pool.html">threadPool</a></div>
<div class="line"><a id="l00022" name="l00022"></a><span class="lineno">   22</span>    {</div>
<div class="line"><a id="l00023" name="l00023"></a><span class="lineno">   23</span>    <span class="keyword">public</span>:</div>
<div class="line"><a id="l00024" name="l00024"></a><span class="lineno">   24</span>    </div>
<div class="line"><a id="l00025" name="l00025"></a><span class="lineno">   25</span>    <span class="keyword">private</span>:</div>
<div class="line"><a id="l00026" name="l00026"></a><span class="lineno">   26</span>        std::vector&lt;std::thread&gt;             m_works__;              <span class="comment">// 线程池</span></div>
<div class="line"><a id="l00027" name="l00027"></a><span class="lineno">   27</span>        std::queue&lt;std::function&lt;void()&gt; &gt;   m_tasks__;              <span class="comment">// 任务队列</span></div>
<div class="line"><a id="l00028" name="l00028"></a><span class="lineno">   28</span>        std::mutex                           m_queue_mutex__;        <span class="comment">// </span></div>
<div class="line"><a id="l00029" name="l00029"></a><span class="lineno">   29</span>        std::condition_variable              m_condition__;         </div>
<div class="line"><a id="l00030" name="l00030"></a><span class="lineno">   30</span>        std::atomic&lt; bool &gt;                  m_stop__;               <span class="comment">// 是否已经停止</span></div>
<div class="line"><a id="l00031" name="l00031"></a><span class="lineno">   31</span>        std::atomic&lt; int &gt;                   m_count__;              <span class="comment">// 线程池容量</span></div>
<div class="line"><a id="l00032" name="l00032"></a><span class="lineno">   32</span>        std::atomic&lt; size_t &gt;                m_max_queue_len__;      <span class="comment">// 队列最大长度</span></div>
<div class="line"><a id="l00033" name="l00033"></a><span class="lineno">   33</span>    <span class="keyword">private</span>:</div>
<div class="line"><a id="l00037" name="l00037"></a><span class="lineno">   37</span>        <span class="keywordtype">void</span> run_task__(){</div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno">   38</span>            <span class="keywordflow">while</span>( !m_stop__.load() ) {</div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno">   39</span>                std::function&lt;void()&gt; task;   <span class="comment">// 实际要执行的任务</span></div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno">   40</span>            </div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno">   41</span>                {</div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno">   42</span>                    std::unique_lock&lt;std::mutex&gt; lock(m_queue_mutex__);</div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno">   43</span>                    m_condition__.wait(lock, [&amp;] {</div>
<div class="line"><a id="l00044" name="l00044"></a><span class="lineno">   44</span>                        <span class="keywordflow">return</span> m_stop__ || !m_tasks__.empty();</div>
<div class="line"><a id="l00045" name="l00045"></a><span class="lineno">   45</span>                    });</div>
<div class="line"><a id="l00046" name="l00046"></a><span class="lineno">   46</span>                    <span class="comment">// 结束执行，这里使用执行完所有的已经排队的线程后才可以退出执行</span></div>
<div class="line"><a id="l00047" name="l00047"></a><span class="lineno">   47</span>                    <span class="keywordflow">if</span> (m_stop__ &amp;&amp; m_tasks__.empty()) {</div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno">   48</span>                        <span class="keywordflow">return</span>;</div>
<div class="line"><a id="l00049" name="l00049"></a><span class="lineno">   49</span>                    }</div>
<div class="line"><a id="l00050" name="l00050"></a><span class="lineno">   50</span>                    <span class="comment">// 拿取任务</span></div>
<div class="line"><a id="l00051" name="l00051"></a><span class="lineno">   51</span>                    task = std::move(m_tasks__.front());</div>
<div class="line"><a id="l00052" name="l00052"></a><span class="lineno">   52</span>                    m_tasks__.pop();</div>
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno">   53</span>                }</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno">   54</span>                <span class="comment">// 执行任务</span></div>
<div class="line"><a id="l00055" name="l00055"></a><span class="lineno">   55</span>                task();</div>
<div class="line"><a id="l00056" name="l00056"></a><span class="lineno">   56</span>            }</div>
<div class="line"><a id="l00057" name="l00057"></a><span class="lineno">   57</span>        }</div>
<div class="line"><a id="l00058" name="l00058"></a><span class="lineno">   58</span>    <span class="keyword">public</span>:</div>
<div class="line"><a id="l00059" name="l00059"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html#ae595e9efa0bb5043299aebb2dc465d8d">   59</a></span>        <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#ae595e9efa0bb5043299aebb2dc465d8d">threadPool</a>(<span class="keywordtype">size_t</span> numThreads) : m_stop__( true ) , m_count__( numThreads ), m_max_queue_len__( 100000 ){}</div>
<div class="line"><a id="l00060" name="l00060"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html#a7fa995c772b6da5982074759457c891e">   60</a></span>        <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a7fa995c772b6da5982074759457c891e">threadPool</a>(<span class="keywordtype">size_t</span> numThreads , <span class="keywordtype">int</span> maxQueue ) : m_stop__( true ) , m_count__( numThreads ), m_max_queue_len__( maxQueue ){}</div>
<div class="line"><a id="l00061" name="l00061"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html#ab28b774736a061198eba7e0a0d5c224f">   61</a></span>        <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#ab28b774736a061198eba7e0a0d5c224f">~threadPool</a>() { <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a9b7e6345ee1a9b2eec83ada50b122c78">stop</a>(); }</div>
<div class="line"><a id="l00070" name="l00070"></a><span class="lineno">   70</span>        <span class="keyword">template</span>&lt;<span class="keyword">class </span>F, <span class="keyword">class</span>... Args&gt;</div>
<div class="foldopen" id="foldopen00071" data-start="{" data-end="}">
<div class="line"><a id="l00071" name="l00071"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html#a74e3439e45bcbbde5dac5fe751daa8cd">   71</a></span>        <span class="keyword">auto</span> <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a74e3439e45bcbbde5dac5fe751daa8cd">enqueue</a>(F&amp;&amp; f, Args&amp;&amp;... args) -&gt; std::future&lt;<span class="keyword">typename</span> std::result_of&lt;F(Args...)&gt;::type&gt; {</div>
<div class="line"><a id="l00072" name="l00072"></a><span class="lineno">   72</span>            <span class="keywordflow">if</span>( m_tasks__.size() &gt;= m_max_queue_len__.load() ){</div>
<div class="line"><a id="l00073" name="l00073"></a><span class="lineno">   73</span>                <span class="keywordflow">throw</span> std::runtime_error( <span class="stringliteral">&quot;队列已经满&quot;</span> );</div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno">   74</span>            }</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno">   75</span>            <span class="keyword">using </span>return_type = <span class="keyword">typename</span> std::result_of&lt;F(Args...)&gt;::type;</div>
<div class="line"><a id="l00076" name="l00076"></a><span class="lineno">   76</span>            </div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno">   77</span>            <span class="keyword">auto</span> task = std::make_shared&lt;std::packaged_task&lt;return_type()&gt;&gt;( std::bind(std::forward&lt;F&gt;(f), std::forward&lt;Args&gt;(args)...) );</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno">   78</span> </div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno">   79</span>            std::future&lt;return_type&gt; res = task-&gt;get_future();</div>
<div class="line"><a id="l00080" name="l00080"></a><span class="lineno">   80</span> </div>
<div class="line"><a id="l00081" name="l00081"></a><span class="lineno">   81</span>            {</div>
<div class="line"><a id="l00082" name="l00082"></a><span class="lineno">   82</span>                std::unique_lock&lt;std::mutex&gt; lock(m_queue_mutex__);</div>
<div class="line"><a id="l00083" name="l00083"></a><span class="lineno">   83</span>            </div>
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno">   84</span>                m_tasks__.emplace([task]() { (*task)(); });</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno">   85</span>            }</div>
<div class="line"><a id="l00086" name="l00086"></a><span class="lineno">   86</span> </div>
<div class="line"><a id="l00087" name="l00087"></a><span class="lineno">   87</span>            m_condition__.notify_one();</div>
<div class="line"><a id="l00088" name="l00088"></a><span class="lineno">   88</span>            <span class="keywordflow">return</span> res;</div>
<div class="line"><a id="l00089" name="l00089"></a><span class="lineno">   89</span>        }</div>
</div>
<div class="line"><a id="l00090" name="l00090"></a><span class="lineno">   90</span>        </div>
<div class="foldopen" id="foldopen00094" data-start="{" data-end="}">
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html#ae4d17e3e1887822be5169301771e8eab">   94</a></span>        <span class="keywordtype">void</span> <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#ae4d17e3e1887822be5169301771e8eab">clearNotRunning</a>(){</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno">   95</span>            std::unique_lock&lt; std::mutex &gt; lock( m_queue_mutex__ );</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno">   96</span>            <span class="keywordflow">while</span>( !m_tasks__.empty() ){</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno">   97</span>                m_tasks__.pop();</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno">   98</span>            }</div>
<div class="line"><a id="l00099" name="l00099"></a><span class="lineno">   99</span>        }</div>
</div>
<div class="foldopen" id="foldopen00104" data-start="{" data-end="}">
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html#a079473d51ebba64f27b45a7a157e2c49">  104</a></span>        <span class="keywordtype">void</span> <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a079473d51ebba64f27b45a7a157e2c49">start</a>( <span class="keywordtype">bool</span> sw = <span class="keyword">true</span> ){</div>
<div class="line"><a id="l00105" name="l00105"></a><span class="lineno">  105</span>            <span class="keywordflow">if</span>( sw ){</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno">  106</span>                <span class="keywordflow">if</span>( !m_stop__.load() ) <span class="keywordflow">return</span>;   <span class="comment">// 线程池正在运行</span></div>
<div class="line"><a id="l00107" name="l00107"></a><span class="lineno">  107</span>                m_stop__ = !sw;</div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno">  108</span>                <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i &lt; m_count__.load(); ++i) {</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno">  109</span>                    m_works__.emplace_back( std::bind( &amp;threadPool::run_task__ , <span class="keyword">this</span> ) );</div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno">  110</span>                }</div>
<div class="line"><a id="l00111" name="l00111"></a><span class="lineno">  111</span>                m_condition__.notify_all();</div>
<div class="line"><a id="l00112" name="l00112"></a><span class="lineno">  112</span>            }<span class="keywordflow">else</span>{</div>
<div class="line"><a id="l00113" name="l00113"></a><span class="lineno">  113</span>                <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#ae4d17e3e1887822be5169301771e8eab">clearNotRunning</a>();</div>
<div class="line"><a id="l00114" name="l00114"></a><span class="lineno">  114</span>                m_stop__ = !sw;</div>
<div class="line"><a id="l00115" name="l00115"></a><span class="lineno">  115</span>                m_condition__.notify_all();</div>
<div class="line"><a id="l00116" name="l00116"></a><span class="lineno">  116</span>                <span class="keywordflow">for</span> (std::thread&amp; worker : m_works__) {</div>
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno">  117</span><span class="preprocessor">#if defined( __GNUC__ )</span></div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno">  118</span>                    pthread_t <span class="keywordtype">id</span> = worker.native_handle();</div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno">  119</span>                    pthread_cancel( <span class="keywordtype">id</span> );</div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno">  120</span><span class="preprocessor">#else</span></div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno">  121</span>                    HANDLE <span class="keywordtype">id</span> = worker.native_handle();</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno">  122</span>                    TerminateThread( <span class="keywordtype">id</span> , 0 );</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno">  123</span><span class="preprocessor">#endif          </span></div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno">  124</span>                }</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno">  125</span>            } </div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno">  126</span>        }</div>
</div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html#a7608e77f566a0471a4afa5a42a9cc639">  130</a></span>        <span class="keywordtype">int</span> <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a7608e77f566a0471a4afa5a42a9cc639">count</a>(){ <span class="keywordflow">return</span> m_count__.load(); }</div>
<div class="foldopen" id="foldopen00135" data-start="{" data-end="}">
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html#a9c16e4135132f173e6e9046fd2d8a837">  135</a></span>        <span class="keywordtype">bool</span> <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a9c16e4135132f173e6e9046fd2d8a837">count</a>( <span class="keywordtype">int</span> <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a7608e77f566a0471a4afa5a42a9cc639">count</a> ){</div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno">  136</span>            <span class="keywordflow">if</span>( !m_stop__.load() ){</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno">  137</span>                <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno">  138</span>            }</div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno">  139</span> </div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno">  140</span>            m_count__ = <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a7608e77f566a0471a4afa5a42a9cc639">count</a>;</div>
<div class="line"><a id="l00141" name="l00141"></a><span class="lineno">  141</span>            <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a id="l00142" name="l00142"></a><span class="lineno">  142</span>        }</div>
</div>
<div class="line"><a id="l00143" name="l00143"></a><span class="lineno">  143</span>           </div>
<div class="line"><a id="l00144" name="l00144"></a><span class="lineno"><a class="line" href="../../dd/d3f/classwheels_1_1thread_pool.html#a9b7e6345ee1a9b2eec83ada50b122c78">  144</a></span>        <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a9b7e6345ee1a9b2eec83ada50b122c78">stop</a>(){ <a class="code hl_function" href="../../dd/d3f/classwheels_1_1thread_pool.html#a079473d51ebba64f27b45a7a157e2c49">start</a>( <span class="keyword">false</span> ); }</div>
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno">  145</span> </div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno">  146</span>    };</div>
</div>
<div class="line"><a id="l00147" name="l00147"></a><span class="lineno">  147</span>}</div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html">wheels::threadPool</a></div><div class="ttdef"><b>定义</b> <a href="#l00021">threadPool.hpp:22</a></div></div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html_a079473d51ebba64f27b45a7a157e2c49"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html#a079473d51ebba64f27b45a7a157e2c49">wheels::threadPool::start</a></div><div class="ttdeci">void start(bool sw=true)</div><div class="ttdoc">启动或者停止线程</div><div class="ttdef"><b>定义</b> <a href="#l00104">threadPool.hpp:104</a></div></div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html_a74e3439e45bcbbde5dac5fe751daa8cd"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html#a74e3439e45bcbbde5dac5fe751daa8cd">wheels::threadPool::enqueue</a></div><div class="ttdeci">auto enqueue(F &amp;&amp;f, Args &amp;&amp;... args) -&gt; std::future&lt; typename std::result_of&lt; F(Args...)&gt;::type &gt;</div><div class="ttdoc">排队任务</div><div class="ttdef"><b>定义</b> <a href="#l00071">threadPool.hpp:71</a></div></div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html_a7608e77f566a0471a4afa5a42a9cc639"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html#a7608e77f566a0471a4afa5a42a9cc639">wheels::threadPool::count</a></div><div class="ttdeci">int count()</div><div class="ttdoc">获取线程池容量</div><div class="ttdef"><b>定义</b> <a href="#l00130">threadPool.hpp:130</a></div></div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html_a7fa995c772b6da5982074759457c891e"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html#a7fa995c772b6da5982074759457c891e">wheels::threadPool::threadPool</a></div><div class="ttdeci">threadPool(size_t numThreads, int maxQueue)</div><div class="ttdef"><b>定义</b> <a href="#l00060">threadPool.hpp:60</a></div></div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html_a9b7e6345ee1a9b2eec83ada50b122c78"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html#a9b7e6345ee1a9b2eec83ada50b122c78">wheels::threadPool::stop</a></div><div class="ttdeci">void stop()</div><div class="ttdef"><b>定义</b> <a href="#l00144">threadPool.hpp:144</a></div></div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html_a9c16e4135132f173e6e9046fd2d8a837"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html#a9c16e4135132f173e6e9046fd2d8a837">wheels::threadPool::count</a></div><div class="ttdeci">bool count(int count)</div><div class="ttdoc">指定线程池容量，修改前线程池需要处于停止状态</div><div class="ttdef"><b>定义</b> <a href="#l00135">threadPool.hpp:135</a></div></div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html_ab28b774736a061198eba7e0a0d5c224f"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html#ab28b774736a061198eba7e0a0d5c224f">wheels::threadPool::~threadPool</a></div><div class="ttdeci">~threadPool()</div><div class="ttdef"><b>定义</b> <a href="#l00061">threadPool.hpp:61</a></div></div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html_ae4d17e3e1887822be5169301771e8eab"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html#ae4d17e3e1887822be5169301771e8eab">wheels::threadPool::clearNotRunning</a></div><div class="ttdeci">void clearNotRunning()</div><div class="ttdoc">清理掉还没有执行的任务</div><div class="ttdef"><b>定义</b> <a href="#l00094">threadPool.hpp:94</a></div></div>
<div class="ttc" id="aclasswheels_1_1thread_pool_html_ae595e9efa0bb5043299aebb2dc465d8d"><div class="ttname"><a href="../../dd/d3f/classwheels_1_1thread_pool.html#ae595e9efa0bb5043299aebb2dc465d8d">wheels::threadPool::threadPool</a></div><div class="ttdeci">threadPool(size_t numThreads)</div><div class="ttdef"><b>定义</b> <a href="#l00059">threadPool.hpp:59</a></div></div>
<div class="ttc" id="anamespacewheels_html"><div class="ttname"><a href="../../df/d8d/namespacewheels.html">wheels</a></div><div class="ttdoc">堆栈信息读取和保存记录</div><div class="ttdef"><b>定义</b> <a href="../../d3/df7/ary__str_8hpp_source.html#l00006">ary_str.hpp:7</a></div></div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.11.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
